<?php
/**
 * ===============================================
 * 版权所有 2019-2050 青岛铁锤科技有限公司，并保留所有权利。
 * 网站地址: http://www.huaxianling.com
 * ===============================================
 * Author: Happy dong
 * Created Time: 2019-12-01 15:50
 *
 * Version: 2.0
 */

namespace App\Modules\Gift\Repositories;


use App\Exceptions\NotFoundException;
use App\Models\Gift;
use Flower\Core\Repository\Eloquent\BaseRepository;

class GiftRepository extends BaseRepository
{
	public function model()
	{
		return Gift::class;
	}


	public function getList(){
		return $this->model->select(['gift.id','gift.name','gift.money','picture.image','gift.status'])
		->leftJoin('picture', 'picture.id', 'gift.image')
		->where(['gift.status'=>1])->get();
	}

	/**
	 * 检测是否存在
	 * @param $id
	 * @return mixed
	 * @throws NotFoundException
	 */
	public function isExisted($id){
		$info = $this->model->select(['gift.id','gift.name','gift.money','picture.image','gift.status'])
			->leftJoin('picture', 'picture.id', 'gift.image')
			->where(['gift.id'=>$id])->first();
		if(empty($info)){
			throw  new NotFoundException(['msg'=>'礼物不存在，请选择存在的礼物']);
		}
		return $info;
	}



}